import axios from 'axios'
// axios.defaults.headers.common['Authorization'] = '';

// 创建axios
const http = axios.create({
    baseURL: '/'
});

// 添加请求拦截器
http.interceptors.request.use(function (config) {

    //过滤空值
    config.params = cleanObject(config.params);

    // 在发送请求之前做些什么
    return config;
}, function (error) {
    // 对请求错误做些什么
    return Promise.reject(error);
});

// 添加响应拦截器
http.interceptors.response.use(function (response) {
    // 对响应数据做点什么
    // console.log('res',response);
    return response;
}, function (error) {
    // 对响应错误做点什么
    return Promise.reject(error);
});
export default http;



export const isFalsy = (value:any) => value === 0 ? false : !value
export const cleanObject = (object:any) => {
    const result = { ...object }
    Object.keys(result).forEach(key => {
        const value = result[key]
        if (isFalsy(value)) {
            delete result[key]
        }
    })
    return result
}
